#!/usr/bin/perl
#exec.cgi

require './remotesync-lib.pl';
&ReadParse();
$job=$in{'sharedir'};

@job1=split(/ /, $job);
$num=@job1;

$job_to_exec=$job1[5];
for($i=6; $i<$num; $i++){

   $job_to_exec=$job_to_exec." ".$job1[$i];

}
$config{'rsynclock'} = "/var/nas/lock/rsync";
my $child_pid=fork;
if(!defined($child_pid)){
	$err_msg = $text{'err_systemerror'};
	goto ERROR_OUT;
}

if ($child_pid) {

        open(RSYNC_LOCK, ">".$config{'rsynclock'});
        print RSYNC_LOCK $child_pid, "\n";
        close(RSYNC_LOCK);
        &redirect("progress.cgi");
}
else {
        #child process
        while(1) {
                if (-s $config{'rsynclock'}) {
                        last;
                }
                sleep(1);
        }
        exec './rsync.pl', $job_to_exec;
}

ERROR_OUT:
&error_setup("ERROR");
&error($err_msg);
